package fileexplorer.commands;

import java.io.File;
import java.util.ArrayList;


import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

import fileexplorer.FileObject;
import fileexplorer.View;

public class Deplacer extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		return null;
	}
	
	public static void move(View view, ArrayList<FileObject> sources, FileObject dest) {
		File dir = new File(dest.getPath());
		if(dir.isDirectory()){
			System.out.println(sources+" => "+dest);
			for(int i=0; i<sources.size(); i++){
				FileObject fileObject = sources.get(i);
				//System.out.println(fileObject.getPath()+" --> "+dest.getPath()+"/"+fileObject.getNom());
				File sourceFile = new File(fileObject.getPath());
				String separator = System.getProperty("file.separator");
				File destFile = new File(dest.getPath()+separator+fileObject.getNom());
				sourceFile.renameTo(destFile);
			}
			view.refreshIconView(view.getUrl());
		}
	}
	
	

}
